def campaigns_and_agents_1():
    Campaign1Group1.LoadCampaign()
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Predict)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Predict)  
    Campaign1Group1.SetDialingMode(optimizeGoal = 50)    
    Campaign1Group1.StartDialing(optimizeGoal = 80)
    CMAg1.Ready()
    Campaign1Group1.StopDialing()
    Campaign1Group1.UnloadCampaign()
    CMAg1.Over()


def campaigns_and_agents_1a():
    Campaign2Group1.LoadCampaign()
    Campaign2Group1.SetDialingMode(optimizeGoal = 60)     
    Campaign2Group1.StartDialing(optimizeGoal = 80)
    Campaign2Group1.SetDialingMode(dialMode = CfgDialMode.Predict)
    Campaign2Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign2Group1.SetDialingMode(dialMode = CfgDialMode.Predict)    
    Campaign2Group1.StopDialing()
    Campaign2Group1.UnloadCampaign()


def campaigns_and_agents_2():
    Campaign2Group1.LoadCampaign()
    Campaign2Group1.SetDialingMode(optimizeGoal = 50)     
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Progress)
    Campaign2Group1.SetDialingMode(dialMode = CfgDialMode.Progress)
    Campaign2Group1.SetDialingMode(optimizeGoal = 60)     
    Campaign2Group1.StartDialing(optimizeGoal = 80)
    Campaign1Group1.LoadCampaign()
    Campaign2Group1.SetDialingMode(dialMode = CfgDialMode.Predict)
    Campaign2Group1.SetDialingMode(dialMode = CfgDialMode.Preview)
    Campaign2Group1.SetDialingMode(dialMode = CfgDialMode.Predict)    
    CMAg1.Ready()
    CMAg1.Over()
    Campaign2Group1.StopDialing()
    Campaign2Group1.UnloadCampaign()
    Campaign1Group1.SetDialingMode(optimizeGoal = 50)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Predict)
    Campaign1Group1.SetDialingMode(dialMode = CfgDialMode.Preview)    
    Campaign1Group1.StartDialing(optimizeGoal = 80)
    CMAg1.Ready()
    CMAg1.Over()
    CMAg1.Ready()
    Campaign1Group1.StopDialing()
    Campaign1Group1.UnloadCampaign()
    CMAg1.Over()

def sequence_campaigns_and_agents_3():
  """CMLib  requests for Sequence Campaign, CommDN and CMLib objects should receive notifications"""

  now =  int(time.mktime(time.localtime(time.time())))
  toStartIn = 15 #sec
  startTime = now + toStartIn 
  timeToWork1 = 60 #sec
  stopAtTime1 = startTime + timeToWork1
  timeToWork2 = 60 #sec
  sleepBeforeNextStart2 = 1 # min 
  stopAtTime2 = stopAtTime1 + sleepBeforeNextStart2*60 +  timeToWork2 
 
  CampaignSequence1.SetStartTime(startTime)
  
  CampaignSequence1.AddScheduleItem(Campaign1Group1, stopAtTime = stopAtTime1  )
  CampaignSequence1.AddScheduleItem(Campaign2Group1, stopAtTime = stopAtTime2 ,  sleepBeforeNextStart = sleepBeforeNextStart2 )
  CampaignSequence1.Load()
  CampaignSequence1.StartDialing()
  CMAg1.Ready()
  CMAg1.Over()
  for Item in CampaignSequence1:
    Item.Loaded()
    Item.DialingStarted()
    CMAg1.Ready()
    CMAg1.Over()
    Item.DialingStopped()
    Item.Unloaded()



